<script>
	import dialog from '@/components/dialog/dialogUtils.js'
	export default {
		onLaunch: function() {
			console.log('App Launch')
			uni['dialog'] = dialog;
			// this.initApp()
			// #ifdef APP-PLUS
			// let timer = setTimeout(function(){
			// 	plus.navigator.closeSplashscreen()
			// 	clearTimeout(timer)
			// },3000)
			// #endif
			
		},
		onShow: function() {
			console.log('App Show')
			// #ifdef APP-PLUS
			plus.screen.lockOrientation("portrait-primary");
			plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
				let currentVersion = widgetInfo.versionCode; //获取当前版本号
				console.log(currentVersion)
				// 有整包更新的话不会进行热更新
				// 安卓整包更新  -跳转h5
				let system = uni.getSystemInfoSync(); // 获取系统信息

				if (system.platform === 'android') {
					uni.request({
						url: 'https://api.aobeitineng.com/version/index',
						method: "POST",
						header: {
							"Content-Type": "application/x-www-form-urlencoded",
						},
						data: {
							version: currentVersion,
							package: 'com.yunduan.aobeitineng',
							type: '2'
						},
						success: (res) => {
							console.log(24, res)
							if (res.data.data) {
								let data = res.data.data
								let newVer = currentVersion.toString()
								let oldVer = data.version_code.toString()
								if (data.is_check = '0' && data.status != '0' && newVer < oldVer) {
									uni.dialog.dialogConfirm(data.content, () => {
										plus.runtime.openURL(data.url);
									}, () => {
										if (data.is_must == '2') {
											plus.runtime.quit();
										}
									} , '立即更新','暂不更新','warning','发现新的版本');
								}
							}
						}
					});
				} else if (system.platform === 'ios') {
					uni.request({
						url: 'https://api.aobeitineng.com/version/index',
						method: "POST",
						header: {
							"Content-Type": "application/x-www-form-urlencoded",
						},
						data: {
							version: currentVersion,
							package: 'com.yunduan.aobeitineng',
							type: '1'
						},
						success: (res) => {
							let data = res.data.data
							let newVer = currentVersion.toString()
							let oldVer = data.version_code.toString()
							console.log(24, res)
							// status’ tinyint(1) NOT NULL DEFAULT1'COMMENT0: 无更新 1: 小版本更新 2: 大版本更新
							// is_check tinyint(2) NOT NULL COMMENT1:审核中 0:开放中，
							if (data.is_check = '0' && data.status != '0' && newVer < oldVer) {
								uni.dialog.dialogConfirm(data.content, () => {
									let appleId = 6446927764
									plus.runtime.launchApplication({
										action: `itms-apps://itunes.apple.com/cn/app/id${appleId}?mt=8`
									}, function(e) {
										console.log(
											'Open system default browser failed: ' +
											e.message);
									});
								}, () => {
									if (data.is_must == '2') {
										plus.ios.import("UIApplication")
											.sharedApplication()
											.performSelector("exit")
									}
								},'立即更新','暂不更新','warning','发现新的版本');
							}
						}
					});
				}
				// 苹果整包更新 -跳转应用市场
				// 热更新


			})
			// #endif
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	/*每个页面公共css */
	page {
		background-color: #F5F5F5;
	}
	/deep/::-webkit-scrollbar {
		display: none;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
	}
	/*checkbox选中后样式  */
	checkbox .uni-checkbox-input {
	  /* border-radius: 50% !important; */
	}
	/*checkbox选中后图标样式  */
	checkbox .uni-checkbox-input.uni-checkbox-input-checked {
		color: #fff;
		background: #FF6E00;;
		border: 1rpx solid #ffffff;
	}
</style>